@extends('backend.layouts.app')

@section('title', $title = '代理收益记录')

@section('breadcrumb')
    <a href="">系统设置</a>
    <a href="">集成系统</a>
    <a href="">{{$title}}</a>
@endsection

@section('content')
    <div class="layui-main">
        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
            <legend>{{$title}}</legend>
        </fieldset>
        <form class="layui-form layui-form-pane" method="GET"
              action="{{ route('agent.earning') }}">
            {{ csrf_field() }}
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">交易时间</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" id="created_at_start" name="created_at_start"
                               placeholder="yyyy-MM-dd HH:mm:ss"
                               value="{{old('created_at_start',$params['created_at_start'])}}">
                    </div>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" id="created_at_end" name="created_at_end"
                               placeholder="yyyy-MM-dd HH:mm:ss"
                               value="{{old('created_at_end',$params['created_at_end'])}}">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">网站名称</label>
                    <div class="layui-input-block">
                        <input type="text" name="site_name" width="200" autocomplete="off"
                               placeholder="请输入网站名称"
                               class="layui-input" value="{{old('site_name',$params['site_name'])}}">
                    </div>
                </div>
                @if(\Auth::user()->type==0)
                    <div class=" layui-inline">
                        <label class="layui-form-label">代理名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="agent_name" width="200" autocomplete="off"
                                   placeholder="请输入代理名称"
                                   class="layui-input" value="{{old('agent_name',$params['agent_name'])}}">
                        </div>
                    </div>
                @endif
                <button class=" layui-btn" lay-submit="" lay-filter="demo1">提交</button>
            </div>


        </form>


        <div class="layui-form">
            @if($earnings->count())
                <table class="layui-table"
                       lay-data="{id:'DeleteTable',totalRow: true,limit:{{$limit+1}}}">
                    <thead>
                    <tr>
                        <th lay-data="{type:'checkbox', fixed: 'left'}">#</th>
                        <th lay-data="{field:'id', width:80, sort: true}">#</th>
                        <th lay-data="{field:'plat_name', width:100,  sort: true}">平台名称</th>
                        <th lay-data="{field:'agent_name', width:100,  sort: true}">代理名称</th>
                        <th lay-data="{field:'site_name', width:100,  sort: true}">网站名称</th>
                        <th lay-data="{field:'rate',  width:100, sort: true}">比率</th>
                        <th lay-data="{field:'money',width:100,  sort: true}">存入金额</th>
                        <th lay-data="{field:'earnings_money', width:100, sort: true}">收益</th>
                        <th lay-data="{field:'before_money', width:100, sort: true}">前代理余额</th>
                        <th lay-data="{field:'after_money', width:100, sort: true}">得到收益后代理余额</th>
                        <th lay-data="{field:'created_at', width:170, sort: true}">创建时间</th>
                        <th lay-data="{field:'updated_at', width:170, sort: true}">修改时间</th>
                    </tr>
                    </thead>
                    <tbody>
                    @foreach($earnings as $index => $earning)
                        <tr>
                            <td></td>
                            <td>{{ $earning->id }}</td>
                            <td>{{ $earning->plat->main_game_plat_name??''  }}</td>
                            <td>{{ $earning->agent->name??''  }}</td>
                            <td>{{ $earning->site->username??''  }}</td>
                            <td>{{ $earning->rate  }}</td>
                            <td>{{ $earning->money }}</td>
                            <td>{{ $earning->earnings_money  }}</td>
                            <td>{{ $earning->before_money  }}</td>
                            <td>{{ $earning->after_money  }}</td>
                            <td>{{ $earning->created_at  }}</td>
                            <td>{{ $earning->updated_at  }}</td>
                        </tr>
                    @endforeach
                    <tr>
                        <td></td>
                        <td>总合计：</td>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td>{{$sumParams['money']}}</td>
                        <td>{{$sumParams['earnings_money']}}</td>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td></td>
                    </tr>
                    </tbody>
                </table>
                <div id="paginate-render"></div>
            @else
                <br/>
                <blockquote class="layui-elem-quote">暂无数据!</blockquote>
            @endif

        </div>
    </div>

@endsection

@section('scripts')
    @include('backend.layouts._paginate',[ 'count' => $earnings->total(), 'delBatchUrl'=>'','limit'=>$limit])
    <script>
        layui.use('laydate', function () {
            var laydate = layui.laydate;

            //日期时间选择器
            laydate.render({
                elem: '#created_at_start'
                , type: 'datetime'
            });

            laydate.render({
                elem: '#created_at_end'
                , type: 'datetime'
            });
        });
    </script>
@endsection
